package net.yla.smartbus.core.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @Author : 默苍离
 * @Create_Date : 2020/08/12/09:20
 * @Pack_name : org.jgs1904 : GetDateString
 * *****************************************************
 * 注释:如果是当天时间，则输出时间，否则输出年月日+时间。
 */
public class GetDateString {

    public static String getDateString(Date date) {

        Date now = new Date();

        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        int i = calendar.get(Calendar.DAY_OF_MONTH);
        calendar.setTime(now);
        int j = calendar.get(Calendar.DAY_OF_MONTH);

        String format = "";

        if (i == j) {
            SimpleDateFormat sdf = new SimpleDateFormat(" HH:mm:ss");
            format = sdf.format(date);
        } else {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
            format = sdf.format(date);
        }

        return format;

    }

}
